import weaviate

client = weaviate.Client("http://192.168.98.128:8080",
                         auth_client_secret=weaviate.AuthApiKey(api_key="WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih"))

where_filter = {
    "path": ["wordCount"],
    "operator": "GreaterThan",
    "valueInt": 1000
}

# 获取并打印schema
schema = client.schema.get()
print(schema)

# 提取所有类名
class_names = [c['class'] for c in schema['classes']]
print("Classes found:", class_names)

# 对于每个类，显示其基本信息（例如类名和属性）
for class_name in class_names:
    print(f"\nClass: {class_name}")
    current_class = next(filter(lambda x: x['class'] == class_name, schema['classes']))
    properties = [p['name'] for p in current_class['properties']]
    print("Properties:", properties)

print("==============================================================================================================")

for class_name in class_names:
    print(f"\nFetching data from class: {class_name}")
    current_class = next(filter(lambda x: x['class'] == class_name, schema['classes']))
    properties = [p['name'] for p in current_class['properties']]

    # 查询该类下的前两个对象的所有属性
    # 构建并执行查询
    query_result = (
      client.query
      .get(class_name, properties)  # 使用具体的属性列表
      #.with_additional(["vector"])  # 请求向量数据
      .with_limit(10)  # 设置一个合理的限制值来控制返回的结果数量
    ).do()  # 执行查询

    if 'errors' in query_result:
        print("Error occurred:", query_result['errors'])
    else:
        objects = query_result.get('data', {}).get('Get', {}).get(class_name, [])
        data = {}
        for obj in objects:
            if obj['dataset_id'] not in data:
                data[obj['dataset_id']] = obj
                print(obj)
            #print(obj)
